Skip to content

DEV-900 Write Verisense RWC as base-station local civil time - #65

Merged
marknolan merged 2 commits into
mainfrom
DEV-900_rwc_local_time
Jul 19, 2026
Merged

DEV-900 Write Verisense RWC as base-station local civil time#65
marknolan merged 2 commits into
mainfrom
DEV-900_rwc_local_time

Conversation

@marknolan

@marknolan marknolan commented Jul 19, 2026

Copy link
Copy Markdown
Member

DEV-900

Problem

The documented Verisense time-sync contract is that the device RWC holds the base station's local time (VERISENSE_COMMUNICATION_PROTOCOL.md: "Synchronises the sensor's real-world clock with the Base Station's local time"). The downstream file parser depends on that domain: midnight/midday CSV splits are evaluated on the raw RWC value in a pinned GMT+0 calendar, and CSV columns are labelled Unix_ms_plus_local_time_zone_offset. The SDK previously had no local-civil helper, so consumers (web console) wrote plain UTC — proven by DEV-793's B9 midnight recording, which never split because device time ran 1 h behind civil time.

Changes

  • utcToLocalCivilMillis() / localCivilUnixSecondsNow() in protocolUtils.ts — the RWC domain conversion (offset evaluated at the instant converted, so DST rules apply correctly).
  • VerisenseClient.writeTimeLocalNow() — one-call correct time sync; returns the seconds written.
  • Domain note on writeTimeUnixSeconds() pointing callers at the new method.
  • formatVerisenseUnixAndHuman() now renders via the Date UTC accessors: a civil-domain value displays verbatim (the browser offset must not be applied a second time).

Tests

New tests/verisense/civil-time.test.ts (offset application incl. DST-instant evaluation, wall-clock round-trip, verbatim rendering, existing guards). Full suite: 241 tests green. Version 0.1.7 → 0.1.8.

Consumer PR: verisense-device-console (same branch name).

🤖 Generated with Claude Code

The documented time-sync contract is that the device RWC holds the base station's LOCAL time (unix + local tz offset), which the downstream file parser depends on for midnight/midday CSV splits (pinned GMT+0 calendar) and 'Local =' header times. Adds utcToLocalCivilMillis()/localCivilUnixSecondsNow() helpers and VerisenseClient.writeTimeLocalNow(), documents the domain on writeTimeUnixSeconds, and switches formatVerisenseUnixAndHuman to the Date UTC accessors so a civil-domain value renders verbatim instead of having the browser offset applied a second time. New tests in tests/verisense/civil-time.test.ts; full suite 241 green. Version 0.1.7 -> 0.1.8.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns Verisense real-world clock (RWC) time-sync behavior with the documented contract that the device clock stores the base station’s local civil time (Unix time with local timezone offset baked in), ensuring downstream CSV splitting/labeling logic operates correctly.

Changes:

  • Added local-civil time helpers (utcToLocalCivilMillis, localCivilUnixSecondsNow) and exported them from the SDK entrypoint.
  • Added VerisenseBleDevice.writeTimeLocalNow() and clarified the domain expectations on writeTimeUnixSeconds().
  • Updated formatVerisenseUnixAndHuman() to render via Date UTC accessors to avoid double-applying timezone offsets; added targeted tests and bumped version to 0.1.8.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/verisense/civil-time.test.ts Adds coverage for offset-at-instant behavior (DST), wall-clock round-trip, and civil-domain rendering.
src/index.ts Exposes the new civil-time helpers via the public SDK exports.
src/devices/verisense/VerisenseClient.ts Adds writeTimeLocalNow() and documents correct RWC domain usage for time sync.
src/devices/verisense/protocolUtils.ts Implements civil-time conversion helpers and switches human formatting to UTC accessors.
package.json Bumps package version to 0.1.8.
package-lock.json Updates lockfile version fields to 0.1.8.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The offset-application assertion compared the millisecond delta against -getTimezoneOffset()*60000, which computes to -0 on a UTC-timezone runner; vitest's toBe uses Object.is, where +0 !== -0, so CI (UTC) failed while local (BST, offset 60) passed. Compare absolute timestamps instead. Verified under TZ=UTC, TZ=Asia/Kuala_Lumpur and host BST; full suite 241 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@marknolan
marknolan merged commit 2a060b2 into main Jul 19, 2026
2 checks passed
@marknolan
marknolan deleted the DEV-900_rwc_local_time branch July 19, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants